<?php

namespace app\admin\model;

use think\Db;

class UserModel extends Model
{
//    public function list()
//    {
//        $user_list = Db::query('
//        SELECT a.*,b.address
//        from `user_info` a
//        LEFT JOIN `user_address` b ON a.address_id = b.id');
//        return $user_list;
//    }

//总条数
    public function count()
    {
//        $list = Db::table('user_info')
//            ->alias('a')
//            ->join('user_address b', 'a.address_id = b.id')->select();
        $list = Db::table('user_info')->select();
        $list_length = count($list);
        return $list_length;
    }

    //分页查询
    public function list($page, $limit)
    {
//        $user_list = Db::table('user_info')
//            ->alias('a')
//            ->join('user_address b', 'a.address_id = b.id')
//            ->page($page, $limit)
//            ->select();
          return Db::table('user_info')->page($page, $limit)->select();
//        return $user_list;
    }

    public function add($data)
    {
        Db::table('user_info')->insert($data);
    }

    public function update($id, $data)
    {
        Db::table('user_info')->where('id=' . $id)->update($data);
    }

    public function delete($id)
    {
        Db::table('user_info')->where('id=' . $id)->delete();
    }

    public function search($user_name)
    {
        return Db::table('user_info')->where('user_name', 'like', '%' . $user_name . '%')->select();
    }
}